package cn.tedu.luban.worker.main.repository;

import cn.tedu.luban.worker.main.converter.WorkerAuditConverter;
import cn.tedu.luban.worker.main.mapper.WorkerAuditLogMapper;
import cn.tedu.luban.worker.protocol.bo.AdminAuditBO;
import cn.tedu.luban.worker.protocol.dos.WorkerAuditLogDO;
import cn.tedu.luban.worker.protocol.param.AuditSubmitParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class WorkerAuditLogRepoImpl implements WorkerAuditLogRepository{
    @Autowired
    private WorkerAuditLogMapper workerAuditLogMapper;
    @Autowired
    private WorkerAuditConverter workerAuditConverter;
    //select * from worker_audit_log where user_id=#{} order by gmt_create
    @Override
    public List<AdminAuditBO> findAuditLogs(Long userId) {
        List<WorkerAuditLogDO> dos=workerAuditLogMapper.selectWorkerAuditLogs(userId);
        return workerAuditConverter.dos2bos(dos);
    }

    @Override
    public Long save(AuditSubmitParam param) {
        log.info("仓储层新增日志 入参:{}",param);
        //param userId是空 导致do转化 userId是空 导致 写入数据库字段user_id是null 导致前台手机端查询详情的日志驳回原因
        //1. 转化
        WorkerAuditLogDO auditDO = workerAuditConverter.param2do(param);
        log.info("审核日志提交写入数据:{}",auditDO);
        //2. 持久层调用写入方法
        workerAuditLogMapper.insert(auditDO);
        return auditDO.getId();
    }
}
